package RunableClass;


import LoadingDialog.ModalProgressDemo;
import RunableClass.useClass.ReadRank;
import RunableSt.authenticator;
import RunnableOldClass.GETThread;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.Authenticator;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Properties;
import STOCK.*;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */



/**
 *
 * @author TOMMYNATO
 */
public class RankRunnable implements Runnable{
    int countRanking=0;
static int count=1;static StringBuffer content = new StringBuffer("");
   int count1=1;public static int avg=0;
    /**
     * @param args the command line arguments
     */
    //public static void main(String[] args) {
          
  //  }

   
  

    @Override
    public void run() {
 
          for(;;){ 
      // GETThread.jLabel6.setText(String.valueOf(countRanking));
           ++ countRanking;
            
       content = new StringBuffer("");int count2=1;
           try {

                
         String buffer;
          String url = " http://www.settrade.com/C13_MarketSummaryRanking.jsp?type=S",
               proxy = "proxy.up.ac.th",
               port = "8080",
               username = "up\\51286885",
               password = "7489250721";

          URL server = new URL(url);

            Authenticator.setDefault(new authenticator(
                        username,password));
            Properties systemProperties = System.getProperties();
            systemProperties.setProperty("http.proxyHost",proxy);
            systemProperties.setProperty("http.proxyPort",port);
            HttpURLConnection connection = (HttpURLConnection)server.openConnection();
            connection.connect();

          BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream(),"TIS-620")) ;
               
               
                while((buffer = in.readLine()) != null) {
                       count2++;
                
                        
                       content.append(count2).append("-->").append(buffer).append("\n");
                       
                  }
            
   
        } catch (Exception ez){
            System.err.println("Couldn't create help URL: " + ez);
        

    }
              
           try {
             int indexcb=  STOCK.cbranktype.getSelectedIndex();
             if(indexcb>0){
                 ReadRank RK=new ReadRank();
             RK.SetDb(content.toString(),STOCK.TbRank,STOCK.cbranktype.getSelectedIndex());
          //   if(WorkControl.isRunning()){
          //        WorkControl.stop();
          //   }
            
            
             }
            Thread.sleep(3000);
            
        } catch (InterruptedException ex) {
        }     STOCK.lbranking.setText("");
              STOCK.cbranktype.setEnabled(true);
          }
    }
}
class SetLine implements ActionListener{
int count=1;
    @Override
    public void actionPerformed(ActionEvent ae) {
      // System.out.println("--");
   //     ModalProgressDemo ModalProgressDemo=new       ModalProgressDemo();
      //  ModalProgressDemo.showProgress();
        if(count==1){
          STOCK.lbranking.setText("waiting."); 
           count++;
        }else if(count==2){
           STOCK.lbranking.setText("waiting.."); 
             count++;
        }else if(count==3){
          STOCK.lbranking.setText("waiting..."); 
            count=1;
        }
      
    }
    
    
    
    
}